package com.gqh.weather.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gqh.weather.domain.entity.StudentAnswer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 学生答题记录Mapper接口
 */
@Mapper
public interface StudentAnswerMapper extends BaseMapper<StudentAnswer> {
    
    /**
     * 根据任务ID、试卷类型和学生ID列表获取答题记录
     *
     * @param taskId 任务ID
     * @param paperType 试卷类型
     * @param studentIds 学生ID列表
     * @return 答题记录列表
     */
    @Select("<script>" +
           "SELECT * FROM zh_student_answer " +
           "WHERE task_id = #{taskId} AND paper_type = #{paperType} " +
           "<if test='studentIds != null and !studentIds.isEmpty()'>" +
           " AND student_id IN " +
           "<foreach item='item' collection='studentIds' open='(' separator=',' close=')'>" +
           "#{item}" +
           "</foreach>" +
           "</if>" +
           " AND is_deleted = 0" +
           "</script>")
    List<StudentAnswer> selectByTaskIdAndPaperTypeAndStudentIds(
        @Param("taskId") Integer taskId,
        @Param("paperType") Integer paperType,
        @Param("studentIds") List<Integer> studentIds);
        
    /**
     * 根据任务ID、试卷类型列表和学生ID列表获取答题记录
     *
     * @param taskId 任务ID
     * @param paperTypes 试卷类型列表
     * @param studentIds 学生ID列表
     * @return 答题记录列表
     */
    @Select("<script>" +
           "SELECT * FROM zh_student_answer " +
           "WHERE task_id = #{taskId} " +
           "<if test='paperTypes != null and !paperTypes.isEmpty()'>" +
           " AND paper_type IN " +
           "<foreach item='item' collection='paperTypes' open='(' separator=',' close=')'>" +
           "#{item}" +
           "</foreach>" +
           "</if>" +
           "<if test='studentIds != null and !studentIds.isEmpty()'>" +
           " AND student_id IN " +
           "<foreach item='item' collection='studentIds' open='(' separator=',' close=')'>" +
           "#{item}" +
           "</foreach>" +
           "</if>" +
           " AND is_deleted = 0" +
           "</script>")
    List<StudentAnswer> selectByTaskIdAndPaperTypesAndStudentIds(
        @Param("taskId") Integer taskId,
        @Param("paperTypes") List<Integer> paperTypes,
        @Param("studentIds") List<Integer> studentIds);
}